<?php

require_once 'CollectionBase.php';

/**
 * Description of Map
 *
 * @author JeyDotC
 */
class Map extends CollectionBase implements Countable, IteratorAggregate, ArrayAccess {
    
    function __construct($type) {
        parent::__construct($type);
    }
    
    public function put($key, $val) {
        if(!$this->isValidType($value))
            throw new InvalidArgumentException ("Incorrect type object");
        
        $this->collection[$key] = $value;
    }
    
    public function get($key){
        if(!$this->containsKey($key))
            throw new InvalidArgumentException("Index '$key' is out of range");
        
        return $this->collection[$key];
    }
    
    public function containsKey($key) {
        return array_key_exists($offset, $this->collection);
    }


    public function remove($key) {
        if(!$this->containsKey($key))
            throw new InvalidArgumentException("Index '$key' is out of range");
        
        unset ($this->collection[$key]);
    }
    
    public function offsetExists($offset) {
        return $this->containsKey($offset);
    }

    public function offsetGet($offset) {
        return $this->get($offset);
    }

    public function offsetSet($offset, $value) {
        $this->put($offset, $value);
    }

    public function offsetUnset($offset) {
        $this->remove($offset);
    }
}

?>
